Trò chơi đua xe động vật trong UNITY Engine
114.933 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 public class ActionScaleTo : TemporalAction {
5
6 private float startX, startY;
7 private float endX, endY;
8
9 public ActionScaleTo() { }
10 public ActionScaleTo(float scaleX, float scaleY, float duration)
11 {
12 SetScaleTo(scaleX, scaleY);
13 SetDuration(duration);
14 }
15 public ActionScaleTo(float scaleX, float scaleY, float duration, Interpolation interpolation)
16 {
17 SetScaleTo(scaleX, scaleY);
18 SetDuration(duration);
19 SetInterpolation(interpolation);
20 }
21
22 protected override void begin()
23 {
24 Vector3 scale = actor.gameObject.transform.localScale;
25 startX = scale.x;
26 startY = scale.y;
27 }
28
29 protected override void end()
30 {
31
32 }
33
34 protected override void UpdateAction(float percent)
35 {
36 //actor.gameObject.transform.localScale.Set(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localScale.z);
37 actor.gameObject.transform.localScale = new Vector3(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localScale.z);
38 }
39
40 public void SetScaleTo(float scaleX, float scaleY)
41 {
42 endX = scaleX;
43 endY = scaleY;
44 }
45 }
2 using System.Collections;
3
4 public class ActionScaleTo : TemporalAction {
5
6 private float startX, startY;
7 private float endX, endY;
8
9 public ActionScaleTo() { }
10 public ActionScaleTo(float scaleX, float scaleY, float duration)
11 {
12 SetScaleTo(scaleX, scaleY);
13 SetDuration(duration);
14 }
15 public ActionScaleTo(float scaleX, float scaleY, float duration, Interpolation interpolation)
16 {
17 SetScaleTo(scaleX, scaleY);
18 SetDuration(duration);
19 SetInterpolation(interpolation);
20 }
21
22 protected override void begin()
23 {
24 Vector3 scale = actor.gameObject.transform.localScale;
25 startX = scale.x;
26 startY = scale.y;
27 }
28
29 protected override void end()
30 {
31
32 }
33
34 protected override void UpdateAction(float percent)
35 {
36 //actor.gameObject.transform.localScale.Set(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localScale.z);
37 actor.gameObject.transform.localScale = new Vector3(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localScale.z);
38 }
39
40 public void SetScaleTo(float scaleX, float scaleY)
41 {
42 endX = scaleX;
43 endY = scaleY;
44 }
45 }
actor.gameObject.transform.localScale.Set(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localScale.z);